<template>
  <div>
      <div style="margin-top: 10%;margin-right: 30%;margin-left: 30%;width:300px">
        <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="标签ID">
                <el-input v-model="form.name"></el-input>
            </el-form-item>
            <el-form-item label="货物类型">
                <el-select v-model="form.ctype" placeholder="请选择活动区域">
                    <el-option
                      v-for="type in ctype_list"
                      :key="type.name"
                      :label="type.name"
                      :value="type.name">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="分配用户">
                <el-select v-model="form.user" placeholder="请选择活动区域">
                    <el-option
                      v-for="user in userlist"
                      :key="user.username"
                      :label="user.username"
                      :value="user.id">
                    </el-option>
                </el-select>
            </el-form-item>              
            <el-form-item>
                <el-button type="primary" @click="onSubmit">立即创建</el-button>
            </el-form-item>
          </el-form>
      </div>
  </div>
</template>

<script>
import { showuser,e_type,add_tag } from '../../../api/api.js';


export default {
  data() {
    return {
      form: {
        name: '',
        ctype:'',   //货物变量
        user:'',    //用户变量

      },
      ctype_list:[],
      userlist:[],
    }
  },

  mounted() {               
    this.show_user_List();
    this.show_type_info();
  },
  methods: {
    onSubmit() {          //提交添加
      var params = {
          tags_id:this.form.name,
          c_type:this.form.ctype,
          create_user:1,
          user_id:this.form.user,   //分配用户
      }
      console.log(params)
      add_tag(params).then(res => {
        alert(res.message);

      })
    },

    show_user_List() {    //查看用户信息
        var params = {
          username : 'admin'
        }
        showuser(params).then(res => {
            this.userlist = res.data
            // console.log(this.userlist,"user");
        })
    },
    show_type_info() {    //查看货物信息
            var params = {
                
            }
            e_type(params).then(res => {
                // console.log(res.data)
                this.ctype_list = res.data
                // console.log(this.ctype_list)                       
            })
        },
  }
}
</script>

<style>

</style>